package com.bjqg.bjqg01.bjqg.activity.longrange.activity;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.bjqg.bjqg01.bjqg.R;
import com.bjqg.bjqg01.bjqg.activity.BaseActivity;
import com.bjqg.bjqg01.bjqg.activity.CommissionedActivity;
import com.bjqg.bjqg01.bjqg.activity.longrange.adapter.MutipleListAdapter;
import com.bjqg.bjqg01.bjqg.activity.longrange.bean.MultipleListBean;
import com.bjqg.bjqg01.bjqg.activity.longrange.dialog.FzDialog;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.DefaultRefreshFooterCreater;
import com.scwang.smartrefresh.layout.api.DefaultRefreshHeaderCreater;
import com.scwang.smartrefresh.layout.api.RefreshFooter;
import com.scwang.smartrefresh.layout.api.RefreshHeader;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
import com.scwang.smartrefresh.layout.header.ClassicsHeader;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadmoreListener;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by bjqg01 on 2018/9/4.
 */

public class MultipleListActivity extends BaseActivity {

    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.tv_top_title_drawer)
    TextView tvTopTitleDrawer;
    @BindView(R.id.tv_search_top_drawer)
    TextView tvSearchTopDrawer;
    @BindView(R.id.smart)
    SmartRefreshLayout smart;
    @BindView(R.id.rc_list)
    RecyclerView rcList;

    MutipleListAdapter adapter;
    List<MultipleListBean> list = new ArrayList<>();
    FzDialog.Builde dialog;
    int number = 4;
    @BindView(R.id.project_information_btn_send)
    Button BtnSend;

    String id;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mutiplelist);
        ButterKnife.bind(this);
        initdata();
        initpost();
        initreash();

    }

    private void initdata() {
        tvTopTitleDrawer.setText(getIntent().getStringExtra("name"));
        id = getIntent().getStringExtra("id");
        tvSearchTopDrawer.setVisibility(View.INVISIBLE);
        tvSearchTopDrawer.setText("新建");


        LinearLayoutManager leftManager = new LinearLayoutManager(this);
        leftManager.setOrientation(LinearLayoutManager.VERTICAL);
        adapter = new MutipleListAdapter(list, MultipleListActivity.this);
        rcList.setLayoutManager(leftManager);
        rcList.setAdapter(adapter);

        adapter.setOnItemClickListener(new MutipleListAdapter.onItemClickListener() {
            @Override
            public void onItem(int position) {
                initfzdialog(position);
                dialog.create().show();
            }
        });

    }

    @OnClick({R.id.back, R.id.tv_search_top_drawer, R.id.project_information_btn_send})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.project_information_btn_send:
                if (id.equals("1")) {
                    Intent tocommentt = new Intent(MultipleListActivity.this, CommissionedActivity.class);
                    tocommentt.putExtra("name", "新建委托-水泥");
                    startActivity(tocommentt);
                } else if (id.equals("2")) {
                    Intent tomultip = new Intent(MultipleListActivity.this, MaterialActivity.class);
                    tomultip.putExtra("name", "新建委托-集料");
                    startActivity(tomultip);
                } else if (id.equals("3")) {
                    Intent toaddi = new Intent(MultipleListActivity.this, AdditiveActivity.class);
                    toaddi.putExtra("name", "新建委托-掺合料及外加剂");
                    startActivity(toaddi);
                } else if (id.equals("4")) {
                    Intent toconcrete = new Intent(MultipleListActivity.this, ConcreteActivity.class);
                    toconcrete.putExtra("name", "新建委托-混凝土及砂浆制品");
                    startActivity(toconcrete);
                } else if (id.equals("5")) {
                    Intent tosteels = new Intent(MultipleListActivity.this, SteelsActivity.class);
                    tosteels.putExtra("name", "新建委托-建筑钢材");
                    startActivity(tosteels);
                } else if (id.equals("6")) {
                    Intent towall = new Intent(MultipleListActivity.this, WallActivity.class);
                    towall.putExtra("name", "新建委托-墙体材料");
                    startActivity(towall);
                } else if (id.equals("7")) {
                    Intent towater = new Intent(MultipleListActivity.this, WaterProofActivity.class);
                    towater.putExtra("name", "新建委托-防水材料");
                    startActivity(towater);
                } else if (id.equals("8")) {
                    Intent towindows = new Intent(MultipleListActivity.this, WindwosActivity.class);
                    towindows.putExtra("name", "新建委托-建筑门窗幕墙");
                    startActivity(towindows);
                } else if (id.equals("9")) {
                    Intent toenrgy = new Intent(MultipleListActivity.this, EnergyActivity.class);
                    toenrgy.putExtra("name", "新建委托-建筑节能材料");
                    startActivity(toenrgy);
                } else if (id.equals("10")) {
                    Intent toelectrical = new Intent(MultipleListActivity.this, ElectricalActivity.class);
                    toelectrical.putExtra("name", "新建委托-建筑电器");
                    startActivity(toelectrical);
                } else if (id.equals("11")) {
                    Intent topipe = new Intent(MultipleListActivity.this, PipeActivity.class);
                    topipe.putExtra("name", "新建委托-管网材料");
                    startActivity(topipe);
                } else if (id.equals("12")) {
                    Intent todec = new Intent(MultipleListActivity.this, DecorateActivity.class);
                    todec.putExtra("name", "新建委托-装饰材料");
                    startActivity(todec);
                }else if (id.equals("13")){
                    Intent todec = new Intent(MultipleListActivity.this, CurrentActivity.class);
                    todec.putExtra("name", "新建委托-通用");
                    startActivity(todec);
                }

                break;
        }
    }

    private void initpost() {
        for (int i = 0; i < 3; i++) {
            String id = "000000" + i;
            String ywtnumber = "000000" + i;
            String wsdjzt = "已完成";
            String ypzt = "" + i;
            String zsbh = "0000001" + i;
            String syzt = "进行中";
            String spzt = "未审批";
            String bgffzt = "未发放";
            list.add(new MultipleListBean(id, ywtnumber, wsdjzt, ypzt, zsbh, syzt, spzt, bgffzt));
        }
        adapter.notifyDataSetChanged();
    }


    private void initreash() {
        SmartRefreshLayout.setDefaultRefreshHeaderCreater(new DefaultRefreshHeaderCreater() {
            @Override
            public RefreshHeader createRefreshHeader(Context context, RefreshLayout layout) {
                //全局设置主题颜色
                layout.setPrimaryColorsId(R.color.white, R.color.colorPrimary);
                //指定为经典Header，默认是 贝塞尔雷达Header
                return new ClassicsHeader(context).setSpinnerStyle(SpinnerStyle.Translate);
            }
        });
        //设置脚布局样式,全局有效
        SmartRefreshLayout.setDefaultRefreshFooterCreater(new DefaultRefreshFooterCreater() {
            @Override
            public RefreshFooter createRefreshFooter(Context context, RefreshLayout layout) {
                //指定为经典Footer，默认是 BallPulseFooter
                return new ClassicsFooter(context).setSpinnerStyle(SpinnerStyle.Translate);
            }
        });

        smart.setEnableLoadmore(true);
        smart.setEnableLoadmoreWhenContentNotFull(true);
//        smart.autoRefresh();//进入界面自动刷新
        smart.setOnRefreshLoadmoreListener(new OnRefreshLoadmoreListener() {
            @Override
            public void onLoadmore(RefreshLayout refreshlayout) {//上拉

            }

            @Override
            public void onRefresh(RefreshLayout refreshlayout) {//下拉

            }
        });
    }

    private void initfzdialog(final int position) {
        dialog = new FzDialog.Builde(MultipleListActivity.this);
        dialog.setCloseListener(new DialogInterface.OnClickListener() {//确定
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (id.equals("1")) {
                    Intent tocommentt = new Intent(MultipleListActivity.this, CommissionedActivity.class);
                    tocommentt.putExtra("name", "新建委托-水泥");
                    startActivity(tocommentt);
                } else if (id.equals("2")) {
                    Intent tomultip = new Intent(MultipleListActivity.this, MaterialActivity.class);
                    tomultip.putExtra("name", "新建委托-集料");
                    startActivity(tomultip);
                } else if (id.equals("3")) {
                    Intent toaddi = new Intent(MultipleListActivity.this, AdditiveActivity.class);
                    toaddi.putExtra("name", "新建委托-掺合料及外加剂");
                    startActivity(toaddi);
                } else if (id.equals("4")) {
                    Intent toconcrete = new Intent(MultipleListActivity.this, ConcreteActivity.class);
                    toconcrete.putExtra("name", "新建委托-混凝土及砂浆制品");
                    startActivity(toconcrete);
                } else if (id.equals("5")) {
                    Intent tosteels = new Intent(MultipleListActivity.this, SteelsActivity.class);
                    tosteels.putExtra("name", "新建委托-建筑钢材");
                    startActivity(tosteels);
                } else if (id.equals("6")) {
                    Intent towall = new Intent(MultipleListActivity.this, WallActivity.class);
                    towall.putExtra("name", "新建委托-墙体材料");
                    startActivity(towall);
                } else if (id.equals("7")) {
                    Intent towater = new Intent(MultipleListActivity.this, WaterProofActivity.class);
                    towater.putExtra("name", "新建委托-防水材料");
                    startActivity(towater);
                } else if (id.equals("8")) {
                    Intent towindows = new Intent(MultipleListActivity.this, WindwosActivity.class);
                    towindows.putExtra("name", "新建委托-建筑门窗幕墙");
                    startActivity(towindows);
                } else if (id.equals("9")) {
                    Intent toenrgy = new Intent(MultipleListActivity.this, EnergyActivity.class);
                    toenrgy.putExtra("name", "新建委托-建筑节能材料");
                    startActivity(toenrgy);
                } else if (id.equals("10")) {
                    Intent toelectrical = new Intent(MultipleListActivity.this, ElectricalActivity.class);
                    toelectrical.putExtra("name", "新建委托-建筑电器");
                    startActivity(toelectrical);
                } else if (id.equals("11")) {
                    Intent topipe = new Intent(MultipleListActivity.this, PipeActivity.class);
                    topipe.putExtra("name", "新建委托-管网材料");
                    startActivity(topipe);
                } else if (id.equals("12")) {
                    Intent todec = new Intent(MultipleListActivity.this, DecorateActivity.class);
                    todec.putExtra("name", "新建委托-装饰材料");
                    startActivity(todec);
                }else if (id.equals("13")){
                    Intent todec = new Intent(MultipleListActivity.this, CurrentActivity.class);
                    todec.putExtra("name", "新建委托-通用");
                    startActivity(todec);
                }
                dialog.dismiss();
            }
        });
        dialog.setConfireListener(new DialogInterface.OnClickListener() {//取消
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
    }

}
